#!/bin/bash
. $HOME/.bashrc
date
echo '-------------'
echo 'step 1/5: update code'
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
cd $DIR
cd ..

changed=1
packagechanged=0
PULLLOG=$(git pull)
echo $PULLLOG
echo $PULLLOG|grep -q "Already up.to.date" && changed=0
echo $PULLLOG|grep -q "package.json" && packagechanged=1
if [ $changed -eq 0 ] && [ "$1" != "force" ];
then
    echo "nothing need todo"
    exit
fi

echo 'step 2/5: install npm package'
#if [ $packagechanged -eq 1 ] && ! [ -d "node_modules" ];
#then
cnpm install
#fi

echo 'step 3/5: build dist files'
npm run build

echo 'step 4/5: copy resources'
cp dist/static/pwa/sw.js dist

echo 'step 5/5: clear old version (latest 10)'

echo 'done.'
